from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-04-10 14:10:13.825775
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 10, Apr, 2021
Time: 14:10:17
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.4763
Nobs: 257.000 HQIC: -48.2194
Log likelihood: 3068.41 FPE: 6.94518e-22
AIC: -48.7192 Det(Omega_mle): 4.92584e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.444604 0.125047 3.555 0.000
L1.Burgenland 0.069097 0.061998 1.115 0.265
L1.Kärnten -0.219951 0.053810 -4.088 0.000
L1.Niederösterreich 0.059371 0.136521 0.435 0.664
L1.Oberösterreich 0.224500 0.127125 1.766 0.077
L1.Salzburg 0.269690 0.069862 3.860 0.000
L1.Steiermark 0.144161 0.089484 1.611 0.107
L1.Tirol 0.117646 0.061256 1.921 0.055
L1.Vorarlberg -0.033945 0.056560 -0.600 0.548
L1.Wien -0.062749 0.115812 -0.542 0.588
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.489236 0.148069 3.304 0.001
L1.Burgenland -0.002640 0.073412 -0.036 0.971
L1.Kärnten 0.331558 0.063716 5.204 0.000
L1.Niederösterreich 0.079837 0.161656 0.494 0.621
L1.Oberösterreich -0.062161 0.150530 -0.413 0.680
L1.Salzburg 0.218521 0.082725 2.642 0.008
L1.Steiermark 0.115272 0.105958 1.088 0.277
L1.Tirol 0.141108 0.072534 1.945 0.052
L1.Vorarlberg 0.153588 0.066973 2.293 0.022
L1.Wien -0.451399 0.137134 -3.292 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.290053 0.061887 4.687 0.000
L1.Burgenland 0.090594 0.030684 2.953 0.003
L1.Kärnten -0.015628 0.026631 -0.587 0.557
L1.Niederösterreich 0.050050 0.067566 0.741 0.459
L1.Oberösterreich 0.282370 0.062916 4.488 0.000
L1.Salzburg 0.021168 0.034576 0.612 0.540
L1.Steiermark 0.024343 0.044287 0.550 0.583
L1.Tirol 0.068652 0.030316 2.265 0.024
L1.Vorarlberg 0.079980 0.027992 2.857 0.004
L1.Wien 0.113352 0.057317 1.978 0.048
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.219735 0.062008 3.544 0.000
L1.Burgenland 0.020439 0.030743 0.665 0.506
L1.Kärnten 0.008717 0.026683 0.327 0.744
L1.Niederösterreich 0.044616 0.067698 0.659 0.510
L1.Oberösterreich 0.405021 0.063039 6.425 0.000
L1.Salzburg 0.082326 0.034643 2.376 0.017
L1.Steiermark 0.132381 0.044373 2.983 0.003
L1.Tirol 0.049810 0.030375 1.640 0.101
L1.Vorarlberg 0.084088 0.028047 2.998 0.003
L1.Wien -0.046851 0.057429 -0.816 0.415
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.506674 0.121133 4.183 0.000
L1.Burgenland 0.086758 0.060057 1.445 0.149
L1.Kärnten 0.010382 0.052125 0.199 0.842
L1.Niederösterreich -0.012286 0.132248 -0.093 0.926
L1.Oberösterreich 0.137107 0.123147 1.113 0.266
L1.Salzburg 0.058374 0.067676 0.863 0.388
L1.Steiermark 0.072634 0.086683 0.838 0.402
L1.Tirol 0.212911 0.059339 3.588 0.000
L1.Vorarlberg 0.031269 0.054790 0.571 0.568
L1.Wien -0.095619 0.112188 -0.852 0.394
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.190347 0.095319 1.997 0.046
L1.Burgenland -0.016417 0.047259 -0.347 0.728
L1.Kärnten -0.008932 0.041017 -0.218 0.828
L1.Niederösterreich -0.026887 0.104066 -0.258 0.796
L1.Oberösterreich 0.410663 0.096904 4.238 0.000
L1.Salzburg 0.015784 0.053254 0.296 0.767
L1.Steiermark -0.008589 0.068211 -0.126 0.900
L1.Tirol 0.157359 0.046694 3.370 0.001
L1.Vorarlberg 0.051883 0.043114 1.203 0.229
L1.Wien 0.240240 0.088280 2.721 0.007
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.240254 0.116625 2.060 0.039
L1.Burgenland 0.019277 0.057822 0.333 0.739
L1.Kärnten -0.067132 0.050186 -1.338 0.181
L1.Niederösterreich -0.066802 0.127327 -0.525 0.600
L1.Oberösterreich 0.019882 0.118564 0.168 0.867
L1.Salzburg 0.081327 0.065157 1.248 0.212
L1.Steiermark 0.338863 0.083457 4.060 0.000
L1.Tirol 0.460676 0.057130 8.064 0.000
L1.Vorarlberg 0.146526 0.052751 2.778 0.005
L1.Wien -0.168459 0.108013 -1.560 0.119
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161904 0.138428 1.170 0.242
L1.Burgenland 0.043501 0.068632 0.634 0.526
L1.Kärnten -0.073658 0.059567 -1.237 0.216
L1.Niederösterreich 0.150549 0.151130 0.996 0.319
L1.Oberösterreich 0.005966 0.140729 0.042 0.966
L1.Salzburg 0.204861 0.077338 2.649 0.008
L1.Steiermark 0.119535 0.099059 1.207 0.228
L1.Tirol 0.056226 0.067811 0.829 0.407
L1.Vorarlberg 0.100906 0.062612 1.612 0.107
L1.Wien 0.235464 0.128205 1.837 0.066
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.579469 0.074906 7.736 0.000
L1.Burgenland -0.037731 0.037138 -1.016 0.310
L1.Kärnten -0.024581 0.032233 -0.763 0.446
L1.Niederösterreich 0.028407 0.081779 0.347 0.728
L1.Oberösterreich 0.324684 0.076151 4.264 0.000
L1.Salzburg 0.020300 0.041849 0.485 0.628
L1.Steiermark -0.035804 0.053603 -0.668 0.504
L1.Tirol 0.088031 0.036694 2.399 0.016
L1.Vorarlberg 0.109766 0.033881 3.240 0.001
L1.Wien -0.045068 0.069374 -0.650 0.516
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.141107 0.054978 0.162523 0.219902 0.072287 0.081471 0.007099 0.155459
Kärnten 0.141107 1.000000 0.026489 0.202669 0.177889 -0.064566 0.161490 0.026997 0.305135
Niederösterreich 0.054978 0.026489 1.000000 0.237637 0.071395 0.315047 0.138781 0.030969 0.302352
Oberösterreich 0.162523 0.202669 0.237637 1.000000 0.299052 0.266017 0.088416 0.061558 0.134258
Salzburg 0.219902 0.177889 0.071395 0.299052 1.000000 0.151442 0.052438 0.089933 0.003403
Steiermark 0.072287 -0.064566 0.315047 0.266017 0.151442 1.000000 0.102976 0.098150 -0.109068
Tirol 0.081471 0.161490 0.138781 0.088416 0.052438 0.102976 1.000000 0.162946 0.147356
Vorarlberg 0.007099 0.026997 0.030969 0.061558 0.089933 0.098150 0.162946 1.000000 -0.001027
Wien 0.155459 0.305135 0.302352 0.134258 0.003403 -0.109068 0.147356 -0.001027 1.000000